package com.voxel.sense.infomsg.module.firm.details.institution.list;

import com.example.com.common.app.BaseRecyclerPresenter;
import com.example.com.common.factory.data.DataSource;
import com.example.com.common.utils.NetworkUtils;
import com.voxel.sense.infomsg.R;
import cyy.example.com.facotry.model.api.BaseEntity;
import cyy.example.com.facotry.model.api.response.InstitutionEntity;
import com.voxel.sense.infomsg.module.firm.details.FirmDtlInfoListContract;
import cyy.example.com.facotry.net.helper.FirmNetHelper;
import cyy.example.com.facotry.Factory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ChenYiYao on 2018/7/26.
 */
public class InstitutionPresenter extends BaseRecyclerPresenter<FirmDtlInfoListContract.View> implements FirmDtlInfoListContract.Presenter {


    public InstitutionPresenter(FirmDtlInfoListContract.View view) {
        super(view);
    }



    @Override
    public void doLoadData(String comdition) {
        mView.showLoading("");
        FirmNetHelper.getInstitutionList(comdition, new DataSource.Callback<BaseEntity<List<InstitutionEntity>>>() {
            @Override
            public void onDataNotAvailable(String strRes, int reqId) {
                if (mView == null)
                    return;
                if (NetworkUtils.isConnected()) {
                    mView.showEmptyView("加载数据失败",true);
                } else {
                    mView.showEmptyView(Factory.app().getString(R.string.network_unavailable),true);
                }
            }

            @Override
            public void onDataLoaded(BaseEntity<List<InstitutionEntity>> data, int reqId) {
                if (mView == null)
                    return;

                if (data.isSuccess()) {
                    List<InstitutionEntity> data1 = data.getData();
                    List lists = new ArrayList();
                    lists.addAll(data1);
                    lists.addAll(data1);
                    lists.addAll(data1);
                    RefreshData(data.getData());
                }else {
                    mView.showEmptyView("加载数据失败",true);
                }

            }
        });
    }
}
